<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>子向父传递数值</title>
  </head>
  <body>
    <div class="box">
      <one></one>
      <next></next>
    </div>
    <script src="../node_modules/vue/dist/vue.js"></script>
    <script>
      var cycle = new Vue()

      Vue.component('one', {
        data: function () {
          return {
            preValue: 'jack',
          }
        },
        template: `
        <div>
        <button @click='fn'>pre单击</button>
        </div>
        `,
        methods: {
          fn() {
            cycle.$emit('myevent', 111)
          },
        },
      })

      Vue.component('next', {
        data: function () {
          return {
            preValue: 'jack',
          }
        },
        template: `
        <div>
       <p>{{preValue}}</p>
        </div>
        `,
        methods: {
          biu() {
            console.log('pre单击l')
          },
        },
        mounted() {
          cycle.$on('myevent', (val) => {
            console.log(val)
          })
        },
      })

      new Vue({
        el: '.box',
        data: {
          value: 10,
        },
        methods: {},
      })
    </script>
  </body>
</html>
